// pages/Pet/PetTravelDetail/PetTravelDetail.js
//获取应用实例
const app = getApp()
const assetsAddress = app.globalData.global.assetsIp + '/' + app.globalData.global.assetsName;
import { queryPetGoddsPicture } from '../../../api/pet';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    safaBtm: wx.getSystemInfoSync().screenHeight - wx.getSystemInfoSync().safeArea.bottom,
    assetsAddress: assetsAddress,
    goods: {},
    bannerList: [], // 商品轮播图列表
    detailList: [], // 商品详情图列表
    isShowPicContent: false, // 是否大图展示商品详情图片
    pictureCont: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.item){
      var item = JSON.parse(options.item)
      console.log(item,'item');
      this.setData({
        goods: item,
      })
      this._queryPetGoddsPicture('0');
      this._queryPetGoddsPicture('1');
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    let userId = wx.getStorageSync('userId') ?? 10;
    return {
      path: '/pages/Welcome/Welcome?scene='+userId,
    }
  },
  // 立即抱团
  submitOrder(){
    let _this = this;
    console.log(_this.data.goods.closeTime,'goods');
    var nowDate = new Date();
    var nowTime = nowDate.getTime();
    var closeIos = _this.data.goods.closeTime.replace(/-/g,'/');
    console.log(closeIos,'closeIos')
    var closeDate = new Date(closeIos);
    var closeTime = closeDate.getTime();
    console.log(closeTime,nowTime,'time')
    if(closeTime < nowTime){
      wx.showToast({
        title: '当前活动报名已结束！',
        icon: 'none',
      })
      return;
    }
    wx.navigateTo({
      url: `/pages/Order/SubmitOrder/SubmitOrder?goods=${JSON.stringify(_this.data.goods)}`,
    })
  },
  // 获取商品图片信息
  _queryPetGoddsPicture(type){
    let _this = this;
    queryPetGoddsPicture({goodsId: _this.data.goods.id,type: type})
    .then(res => {
      if(res.success){
        if(type == '1'){
          _this.setData({
            bannerList: res.data.content,
          })
        }else{
          _this.setData({
            detailList: res.data.content,
          })
        }
      }else{
        wx.showToast({
          title: res.errMessage,
          icon: 'none',
        })
      }
    })
  },
  // 点击轮播图片
  showBannerPic(e){
    console.log(e,'点击轮播')
    var imgUrl = JSON.parse(e.detail);
    this.setData({
      pictureCont: imgUrl,
    })
    this.showPicCont();
  },
  // 点击图片
  showPic(e){
    let item = e.target.dataset.item||e.currentTarget.dataset.item;
    console.log(item,'item');
    this.setData({
      pictureCont: item,
    })
    this.showPicCont();
  },
  // 打开、关闭图片
  showPicCont(){
    let _this = this;
    console.log(_this.data.isShowPicContent,'isShowPicContent')
    _this.setData({
      isShowPicContent: !_this.data.isShowPicContent,
    })
  },
})